package com.bash;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class QuoteDataAdapter extends ArrayAdapter<QuoteData>
{
	int resource;
	
	public QuoteDataAdapter(Context _context, int _resource) {
		super(_context, _resource);
		resource = _resource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		LinearLayout row;
		QuoteData item = getItem(position);
		
		if (convertView == null) {
			row = new LinearLayout(getContext());
			LayoutInflater vi;
			vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			vi.inflate(resource, row, true);
		} else {
			row = (LinearLayout)convertView;
		}

		TextView quoteId = (TextView)row.findViewById(R.id.quoteId);
		quoteId.setText("QDB #"+ item.getQid().toString());

		TextView quoteRating = (TextView)row.findViewById(R.id.quoteRating);
		quoteRating.setText("Rating: "+ item.getRating().toString());

		TextView text = (TextView)row.findViewById(R.id.quoteText);
		text.setText(item.toString());
		
		return row;
	}
}